home *** CD-ROM | disk | FTP | other *** search
- /*
- *=============================================================================
- * tSippPrim.c
- *-----------------------------------------------------------------------------
- * Tcl commands to create basic SIPP primitive objects.
- *-----------------------------------------------------------------------------
- * Copyright 1992 Mark Diekhans
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies. Mark Diekhans makes
- * no representations about the suitability of this software for any purpose.
- * It is provided "as is" without express or implied warranty.
- *-----------------------------------------------------------------------------
- * $Id: tSippPrim.c,v 2.0 1992/11/02 03:56:31 markd Rel $
- *=============================================================================
- */
-
- #include "tSippInt.h"
-
- /*=============================================================================
- * SippTorus --
- * Implements the command:
- * SippTorus bigradius smallradius radialres tuberes shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippTorus (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double bigRadius, smallRadius;
- unsigned radialRes, tubeRes;
- int texture = NATURAL;
-
- if ((argc < 6) || (argc > 7)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " bigradius smallradius radialres tuberes ",
- "shaderhandle [texture]", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [1], &bigRadius))
- return TCL_ERROR;
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [2], &smallRadius))
- return TCL_ERROR;
- if (smallRadius >= bigRadius) {
- Tcl_AppendResult (interp, "big radius must be greater than small ",
- "radius", (char *) NULL);
- return TCL_ERROR;
- }
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [3], &radialRes))
- return TCL_ERROR;
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [4], &tubeRes))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [5],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 7) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [6], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_torus (bigRadius, smallRadius, radialRes,
- tubeRes, surfDescPtr, shaderPtr,
- texture));
-
- return TCL_OK;
-
- } /* SippTorus */
-
- /*=============================================================================
- * SippCone --
- * Implements the command:
- * SippCone bottomradius topradius length resolution shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippCone (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double bottomRadius, topRadius, length;
- unsigned resolution;
- int texture = NATURAL;
-
- if ((argc < 6) || (argc > 7)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0], " bottomgradius",
- " topradius length resolution shaderhandle ",
- "[texture]", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [1], &bottomRadius))
- return TCL_ERROR;
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [2], &topRadius))
- return TCL_ERROR;
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [3], &length))
- return TCL_ERROR;
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [4], &resolution))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [5],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 7) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [6], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_cone (bottomRadius, topRadius, length,
- resolution, surfDescPtr, shaderPtr,
- texture));
-
- return TCL_OK;
-
- } /* SippCone */
-
- /*=============================================================================
- * SippCylinder --
- * Implements the command:
- * SippCylinder radius length resolution shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippCylinder (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double radius, length;
- int resolution, texture = NATURAL;
-
- if ((argc < 5) || (argc > 6)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " radius length resolution shaderhandle [texture]",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [1], &radius))
- return TCL_ERROR;
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [2], &length))
- return TCL_ERROR;
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [3], &resolution))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [4],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 6) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [5], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_cylinder (radius, length, resolution,
- surfDescPtr, shaderPtr,
- texture));
- return TCL_OK;
-
- } /* SippCylinder */
-
- /*=============================================================================
- * SippEllipsoid --
- * Implements the command:
- * SippEllipsoid {xradius yradius zradius} resolution shaderhandle
- * [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippEllipsoid (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- Vector radius;
- unsigned resolution;
- int texture = NATURAL;
-
- if ((argc < 4) || (argc > 5)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " {xradius yradius zradius} resolution ",
- "shaderhandle [texture]", (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertVertex (tSippGlobPtr, argv [1], &radius))
- return TCL_ERROR;
- if ((radius.x <= 0.0) || (radius.y <= 0.0) || (radius.z <= 0.0)) {
- Tcl_AppendResult (tSippGlobPtr->interp, " radius X Y and Z must be ",
- " > 0.0", (char *) NULL);
- return TCL_ERROR;
- }
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [2], &resolution))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [3],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 5) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [4], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_ellipsoid (radius.x, radius.y, radius.z,
- resolution, surfDescPtr,
- shaderPtr, texture));
- return TCL_OK;
-
- } /* SippEllipsoid */
-
- /*=============================================================================
- * SippSphere --
- * Implements the command:
- * SippSphere radius resolution shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippSphere (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double radius;
- int resolution, texture = NATURAL;
-
- if ((argc < 4) || (argc > 5)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " radius resolution shaderhandle [texture]",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [1], &radius))
- return TCL_ERROR;
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [2], &resolution))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [3],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 5) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [4], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_sphere (radius, resolution,
- surfDescPtr, shaderPtr, texture));
- return TCL_OK;
-
- } /* SippSphere */
-
- /*=============================================================================
- * SippPrism --
- * Implements the command:
- * SippPrism 2dpointlist length shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippPrism (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double length;
- int listArgc, idx;
- char **listArgv;
- Vector *pointList;
- int texture = NATURAL;
-
- if ((argc < 4) || (argc > 5)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " 2dpointlist length shaderhandle [texture]",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- if (Tcl_SplitList (tSippGlobPtr->interp, argv [1], &listArgc,
- &listArgv) != TCL_OK)
- return TCL_ERROR;
-
- if (listArgc < 3) {
- ckfree (listArgv);
- Tcl_AppendResult (interp, "2d point list must contain at least 3 ",
- "points", (char *) NULL);
- return TCL_ERROR;
- }
-
- pointList = (Vector *) ckalloc (listArgc * sizeof (Vector));
-
- for (idx = 0; idx < listArgc; idx++) {
- if (!TSippConvert2DPoint (tSippGlobPtr, listArgv [idx],
- &pointList [idx].x, &pointList [idx].y))
- goto errorExit;
- pointList [idx].z = 0.0;
- }
-
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [2], &length))
- goto errorExit;
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [3],
- &surfDescPtr);
- if (shaderPtr == NULL)
- goto errorExit;
-
- if (argc == 5) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [4], &texture, NULL))
- goto errorExit;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_prism (listArgc, pointList, length,
- surfDescPtr, shaderPtr, texture));
- ckfree (pointList);
- ckfree (listArgv);
- return TCL_OK;
- errorExit:
- ckfree (pointList);
- ckfree (listArgv);
- return TCL_ERROR;
-
- } /* SippPrism */
-
- /*=============================================================================
- * SippBlock --
- * Implements the command:
- * SippBlock {xsize ysize zsize} shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippBlock (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- Vector sizes;
- int texture = NATURAL;
-
- if ((argc < 3) || (argc > 4)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " {xsize ysize zsize} shaderhandle [texture]",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertVertex (tSippGlobPtr, argv [1], &sizes))
- return TCL_ERROR;
- if ((sizes.x <= 0.0) || (sizes.y <= 0.0) || (sizes.z <= 0.0)) {
- Tcl_AppendResult (tSippGlobPtr->interp, " sizes X Y and Z must be ",
- " > 0.0", (char *) NULL);
- return TCL_ERROR;
- }
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [2],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 4) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [3], &texture, NULL))
- return TCL_ERROR;
- }
-
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_block (sizes.x, sizes.y, sizes.z,
- surfDescPtr, shaderPtr, texture));
- return TCL_OK;
-
- } /* SippBlock */
-
- /*=============================================================================
- * SippCube --
- * Implements the command:
- * SippCube size shaderhandle [texture]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- int
- SippCube (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Shader *shaderPtr;
- void *surfDescPtr;
- double size;
- int texture = NATURAL;
-
- if ((argc < 3) || (argc > 4)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " size shaderhandle [texture]", (char *) NULL);
- return TCL_ERROR;
- }
- if (!TSippConvertUnsignedDbl (tSippGlobPtr, argv [1], &size))
- return TCL_ERROR;
-
- shaderPtr = TSippShaderHandleToPtr (tSippGlobPtr, argv [2],
- &surfDescPtr);
- if (shaderPtr == NULL)
- return TCL_ERROR;
-
- if (argc == 4) {
- if (!TSippParseTextureMapping (tSippGlobPtr, argv [3], &texture, NULL))
- return TCL_ERROR;
- }
- TSippBindObjectToHandle (tSippGlobPtr,
- sipp_cube (size, surfDescPtr, shaderPtr,
- texture));
- return TCL_OK;
-
- } /* SippCube */
-
- /*=============================================================================
- * TSippPrimInit --
- * Initialized the primitve object creation commands.
- *
- * Parameters:
- * o tSippGlobPtr (I) - Pointer to the top level global data structure.
- *-----------------------------------------------------------------------------
- */
- void
- TSippPrimInit (tSippGlobPtr)
- tSippGlob_pt tSippGlobPtr;
- {
- static tSippTclCmdTbl_t cmdTable [] = {
- {"SippTorus", SippTorus},
- {"SippCone", SippCone},
- {"SippCylinder", SippCylinder},
- {"SippEllipsoid", SippEllipsoid},
- {"SippSphere", SippSphere},
- {"SippPrism", SippPrism},
- {"SippBlock", SippBlock},
- {"SippCube", SippCube},
- {NULL, NULL}
- };
-
- TSippInitCmds (tSippGlobPtr, cmdTable);
-
- } /* TSippPrimInit */
-
-
-